//
//  VisitorLoginView.swift
//  Weibo
//
//  Created by 张文文 on 15/5/28.
//  Copyright (c) 2015年 zww. All rights reserved.
//

import UIKit


//自定义协议方法

protocol VisitorLoginViewDelegate: NSObjectProtocol {
    //点击登陆按钮
    func visitorViewLoginViewDidSelected()
    //点击注册按钮
    func visitorViewregisterViewDidSelected()
}

class VisitorLoginView: UIView {

    @IBOutlet weak var smallIconView: UIImageView!
    
    @IBOutlet weak var iconView: UIImageView!

    @IBOutlet weak var messageLabel: UILabel!
    
    ///定义代理
    weak var delegate:VisitorLoginViewDelegate?
    
    
    // 首页不需要其他页面需要
    // 传递参数的时候，可以指定一个默认值，好处，不需要到处修改代码
    func setupInfo(imageName: String, message: String, isHome: Bool = false ){
        
        iconView.hidden = !isHome
        
        if isHome {
            iconView.image = UIImage(named: imageName)
            startAnimation()
        }
        else {
            smallIconView.image = UIImage(named: imageName)
        }
        
        messageLabel.text = message
        
//        isHome ? startAnimation(): stopAnimation()
        
        
    }
    ///开始动画
    func startAnimation(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = 2 * M_PI
        anim.repeatCount = MAXFLOAT
        anim.duration = 20.0
        
        smallIconView.layer.addAnimation(anim, forKey: nil)
    }
    ///停止动画
    func stopAnimation(){
        
        smallIconView.layer.removeAllAnimations()
    }
    
  
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    @IBAction func register() {
        delegate?.visitorViewregisterViewDidSelected()
    }
    @IBAction func login() {
        delegate?.visitorViewLoginViewDidSelected()
    }
    
    
}
